package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JdbcDemo08 {
    public static void main(String[] args) {
        userinfo userinfo = InputUtil.getInputObject(new userinfo(),"欢迎注册","注册");

        try (
                Connection connection = DbUtil.getConnection();
                ){
            String sql = "INSERT INFO (username,password,nickname,age) " +
                    "VALUES(?,?,?,?) ";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,userinfo.getUsername());
            ps.setString(2,userinfo.getPassword());
            ps.setString(3,userinfo.getNickname());
            ps.setInt(4,userinfo.getAge());
            int num = ps.executeUpdate();
            if (num>0){
                System.out.println("注册成功");
            }else {
                System.out.println("注册失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
